var express = require("express");
var server = express();
var query = require("querystring");
server.listen(3000,function(){
	console.log("3000")
})
server.get("*",function(req,res){
	console.log(req.url);
	res.header('Access-Control-Allow-Origin','*');
	console.log(1111)
	res.sendFile(__dirname+req.url)
})
//登陆
server.post("/login",function (req,res) {
    res.header("Access-Control-Allow-Origin","*");
    console.log("收到post");
    req.on("data",function (data) {
        console.log("这是"+data)
    });
    req.on("end",function () {
        for (var i = 0; i<arr.length; i++) {
        if (req.query.username==arr[i].username&&req.query.pwd==arr[i].pwd) {
            bl=true
            // console.log(true);
        } else{
            bl=false
        };
    };
    res.send(bl)
    });
})
//注册
var arr=[];
server.post("/register",function (req,res) {
res.header("Access-Control-Allow-Origin","*");
console.log("收到post");
var param="";
req.on("data",function (data) {
    param+=data;
});
req.on("end",function () {
    // console.log(param);
    var trs=query.parse(param)
        arr.push(trs)
        res.send(arr)
});
});
